package com.example.aidlserver;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import com.example.aidlserver.aidl.Book;

import java.util.ArrayList;
import java.util.List;

public class RemoteServer extends Service {
    List<Book> bookList= new ArrayList<>();
    IBinder iBinder = new InterBookManager.Stub() {
        @Override
        public List<Book> getBooks() throws RemoteException {
            return bookList;
        }

        @Override
        public void addBook(Book book) throws RemoteException {
            bookList.add(book);
            Intent intent = new Intent("remoteserver.addbook");
            intent.putExtra("book",book);
            sendBroadcast(intent);
        }
    };
    @Override
    public IBinder onBind(Intent intent) {

        return iBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }
}
